﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDataBaseWork;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.dbEntity;
using XF.Meeting.Entity.DTO;
using XF.Meeting.Entity.Query;
using XF.Meeting.Entity.View;
using XF.Meeting.IDal;

namespace XF.Meeting.DAL
{
    public class MeetingDal : BaseDAL, IMeetingDal
    {
        #region 任务方法
        public Task<bool> UpdateMeeting(DateTime dt, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@dateTime",dt),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateMeetingState", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateMeetingState EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }
        public Task<bool> UpdateMeeting_E(DateTime dt, out DataTable d, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@dateTime",dt),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateMeetingState_E", out DataSet ds, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateMeetingState EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (ds.Tables.Count > 0)
            {
                d = ds.Tables[0];
            }
            else
            {
                d = new DataTable();
            }

            return Task.FromResult(bResult);
        }
        public Task<bool> updateWxState(int CinfoId, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CinfoId",CinfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateWxState", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateWxState EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }
        public Task<bool> UpdateWXEndState(int CinfoId, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CinfoId",CinfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateWXEndState", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateWXEndState EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }
        public bool IsSendWX(int CinfoId, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CinfoId",CinfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spIsSendWX", out int ReturnValue, out strError))
            {

                strError = string.Format("DBProvider spIsSendWX EXECUTE_DB Error:{0}", strError);
                return false;
            }
            else
            {
                strError = string.Empty;
            }
            return ReturnValue > 0;
        }
        public Task<bool> MeetUpdateEnd(int CinfoId, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CinfoId",CinfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spMeetUpdateEnd", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spMeetUpdateEnd EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        public DataSet getMeetInfoAndUserPhone(int iD, out string StrError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
              new SqlParameter("@CInfoId",iD)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetMeeetUserPhone", out DataSet DS, out StrError))
            {

                StrError = string.Format("DBProvider spGetUserListForWX EXECUTE_DB Error:{0}", StrError);
            }
            else
            {
                StrError = string.Empty;
            }
            return DS;
        }
        public DataSet GetMeeetUserPhoneFromOrgcalendars(int iD, out string StrError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
              new SqlParameter("@ID",iD)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetMeeetUserPhoneFromOrgcalendars", out DataSet DS, out StrError))
            {

                StrError = string.Format("DBProvider spGetMeeetUserPhoneFromOrgcalendars EXECUTE_DB Error:{0}", StrError);
            }
            else
            {
                StrError = string.Empty;
            }
            return DS;
        }

        public Task<DataTable> GetUserListForWX(DateTime dt, out string StrError)
        {
            var SEDate = dt.AddMinutes(10);
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@dateTime",dt),
                  new SqlParameter("@SedateTime",SEDate),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetUserListForWX", out DataSet DS, out StrError))
            {
                StrError = string.Format("DBProvider spGetUserListForWX EXECUTE_DB Error:{0}", StrError);
            }
            else
            {
                StrError = string.Empty;
            }
            return Task.FromResult(DS.Tables[0]);
        }
        public Task<DataTable> GetUserListForMeetEnd(DateTime dt, out string StrError)
        {
            var EndTime = dt.AddMinutes(15);
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@dateTime",dt),
                  new SqlParameter("@EndTime",EndTime),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetUserListForMeetEnd", out DataSet DS, out StrError))
            {
                StrError = string.Format("DBProvider spGetUserListForWX EXECUTE_DB Error:{0}", StrError);
            }
            else
            {
                StrError = string.Empty;
            }
            return Task.FromResult(DS.Tables[0]);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="croomId"></param>
        /// <param name="userId"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetCInfoByRoomIdAndUserId(string croomId, string userId, out string strError)
        {


            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RoomId",croomId),
                   new SqlParameter("@UserId",userId)

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoByRoomIdAndUserId", out DataSet ds, out strError))
            {

                strError = string.Format("DBProvider spGetCInfoByRoomIdAndUserId EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(ds.Tables[0]);
        }
        #endregion
        /// <summary>
        /// 添加会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> AddMeetingRoom(MeetingRoomOrder entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RID",entity.RID),
                  new SqlParameter("@SAID",entity.SAID),
                  new SqlParameter("@CEquipmentIDs",entity.CEquipmentIDs==null?"":entity.CEquipmentIDs),
                  new SqlParameter("@ConferenceName",entity.ConferenceName==null?"":entity.ConferenceName),
                  new SqlParameter("@HoldNumber",entity.HoldNumber),
                  new SqlParameter("@State",entity.State),
                  new SqlParameter("@Admin",entity.Admin),
                  new SqlParameter("@AppointmentProcess",entity.AppointmentProcess),
                  new SqlParameter("@IsSignOn",entity.IsSignOn),
                  new SqlParameter("@InfraredDetection",entity.InfraredDetection==null?"":entity.InfraredDetection),
                  new SqlParameter("@TerminalShort",entity.TerminalShort),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                  new SqlParameter("@Remark",entity.Remark==null?"":entity.Remark),
                  new SqlParameter("@FileName",entity.FileName==null?"":entity.FileName),
                  new SqlParameter("@FileUrl",entity.FileUrl==null?"":entity.FileUrl),
                  new SqlParameter("@StrategyState",entity.StrategyState),
                   new SqlParameter("@IsTurnOn",entity.IsTurnOn),
                    new SqlParameter("@AutoWechat",entity.AutoWeChat),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertConferenceRoom", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertConferenceRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 根据会议室ID查看会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetMeetingRoomByID(MeetingRoomQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",query.ID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        public Task<DataTable> GetAllGMSRoom(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",2),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllGMSRoom", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllGMSRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        /// <summary>
        /// 会议室（编辑）
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateMeetingRoomByID(MeetingRoomOrder entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@RID",entity.RID),
                  //new SqlParameter("@SAID",entity.SAID),
                  new SqlParameter("@CEquipmentIDs",entity.CEquipmentIDs??""),
                  new SqlParameter("@ConferenceName",entity.ConferenceName??""),
                  new SqlParameter("@HoldNumber",entity.HoldNumber),
                  new SqlParameter("@State",entity.State),
                  new SqlParameter("@Admin",entity.Admin),
                  new SqlParameter("@AppointmentProcess",entity.AppointmentProcess),
                  new SqlParameter("@IsSignOn",entity.IsSignOn),
                  new SqlParameter("@InfraredDetection",entity.InfraredDetection??""),
                  new SqlParameter("@TerminalShort",entity.TerminalShort),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                  new SqlParameter("@Remark",entity.Remark??""),
                  new SqlParameter("@FileName",entity.FileName??""),
                  new SqlParameter("@FileUrl",entity.FileUrl??""),
                  new SqlParameter("@AutoWechat",entity.AutoWeChat),
                  new SqlParameter("@StrategyState",entity.StrategyState),
                  new SqlParameter("@IsTurnOn",entity.IsTurnOn)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceRoom", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 删除会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> DeleteMeetingRoom(MeetingRoomQuery entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spDeleteCRoom", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteCRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 会议纪要（手动创建）
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<bool, int>> MinutesOrder(MeetingOrder entity, out string strError)
        {
            bool bResult = true;


            if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            {
                string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
                                                             //第一个为主会议室

                entity.CRoomID = Convert.ToInt32(arrStr[0]);
                ArrayList list = new ArrayList(arrStr);
                list.RemoveAt(0);
                entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            }



            entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
            entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);
            if (entity.IsMinutesApproval == false)
            {
                entity.MinutesState = 1;
            }

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CostomCRoom",entity.CostomCRoom),
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs??""),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs??""),
                  new SqlParameter("@CopyIDs",entity.CopyIDs??""),
                  new SqlParameter("@CreatorID",entity.CreatorID),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme??""),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@Outsiders",entity.Outsiders??""),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                  new SqlParameter("@IsMinutesApproval",entity.IsMinutesApproval),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark??""),
                  new SqlParameter("@MinutesState",entity.MinutesState),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertConferenceMinutes", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertConferenceMinutes EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (entity.files.Count > 0)
            {
                foreach (var item in entity.files)
                {
                    SqlParameter[] sqlParametersNew = new SqlParameter[] {
                  new SqlParameter("@MinutesID",ReturnValue),
                  new SqlParameter("@FileName",item.FileName==null?"":item.FileName),
                  new SqlParameter("@FileUrl",item.FileUrl==null?"":item.FileUrl),

                };
                    CParameters parasNew = new CParameters();
                    parasNew.AddRange(sqlParametersNew);
                    if (!_db.ExcuteByTransaction(parasNew, "spInsertMinutes_File_Map", out int ReturnValue1, out strError))
                    {
                        bResult = false;
                        strError = string.Format("DBProvider spInsertMinutes_File_Map EXECUTE_DB Error:{0}", strError);
                        return Task.FromResult(new Tuple<bool, int>(bResult, -1));
                    }
                    else
                    {
                        strError = string.Empty;
                    }
                }
            }
            return Task.FromResult(new Tuple<bool, int>(bResult, ReturnValue));
        }

        /// <summary>
        /// 会议纪要（编辑）
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateConferenceMinutes(MeetingOrder entity, out string strError)
        {
            bool bResult = true;

            SqlParameter[] sqlParametersNew1 = new SqlParameter[] {
                  new SqlParameter("@MinutesID",entity.ID),


                };
            CParameters parasNew1 = new CParameters();
            parasNew1.AddRange(sqlParametersNew1);
            if (!_db.ExcuteByTransaction(parasNew1, "spDeleteMinutes_File_Map", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteMinutes_File_Map EXECUTE_DB Error:{0}", strError);
                return Task.FromResult(bResult);
            }
            else
            {
                strError = string.Empty;
            }

            foreach (var item in entity.files)
            {
                if (item.FileUrl != "" && item.FileUrl != "")
                {
                    SqlParameter[] sqlParametersNew = new SqlParameter[] {
                  new SqlParameter("@MinutesID",entity.ID),
                  new SqlParameter("@FileName",item.FileName==null?"":item.FileName),
                  new SqlParameter("@FileUrl",item.FileUrl==null?"":item.FileUrl),

                };
                    CParameters parasNew = new CParameters();
                    parasNew.AddRange(sqlParametersNew);
                    if (!_db.ExcuteByTransaction(parasNew, "spInsertMinutes_File_Map", out int ReturnValue2, out strError))
                    {
                        bResult = false;
                        strError = string.Format("DBProvider spInsertMinutes_File_Map EXECUTE_DB Error:{0}", strError);
                        return Task.FromResult(bResult);
                    }
                    else
                    {
                        strError = string.Empty;
                    }
                }

            }
            if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            {
                string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
                                                             //第一个为主会议室

                entity.CRoomID = Convert.ToInt32(arrStr[0]);
                ArrayList list = new ArrayList(arrStr);
                list.RemoveAt(0);
                entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            }

            if (entity.IsMinutesApproval == false)
            {
                entity.MinutesState = 2;
            }
            else
            {
                entity.MinutesState = 1;
            }

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@CostomCRoom",entity.CostomCRoom),
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs==null?"":entity.CRoomIDs),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs==null?"":entity.ParticipantIDs),
                  new SqlParameter("@CopyIDs",entity.CopyIDs==null?"":entity.CopyIDs),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@IsSubmitOnTime",entity.IsSubmitOnTime),
                  new SqlParameter("@Outsiders",entity.Outsiders==null?"":entity.Outsiders),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                  new SqlParameter("@IsMinutesApproval",entity.IsMinutesApproval),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark==null?"":entity.ConferenceRemark),
                   new SqlParameter("@MinutesState",entity.MinutesState),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceMinutes", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceMinutes EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }


            return Task.FromResult(bResult);
        }

        /// <summary>
        ///获取会议纪要列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetCInfoMinutesList(CInfoQuery query, out string strError)
        {
            int TotalRowsCount = 0;
            int TotalPageCount = 0;
            DataSet ds = new DataSet();

            if (query.MinutesState < 0)
            {
                SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),

                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@ConferenceType",query.ConferenceType),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                  new SqlParameter("@MinutesState",query.MinutesState),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
                CParameters paras = new CParameters();
                paras.AddRange(sqlParameters);

                if (!_db.ExcuteByTransaction(paras, "spGetCInfoMinutesListAll", out TotalRowsCount, out TotalPageCount, out ds, out strError))
                {
                    strError = string.Format("DBProvider spGetCInfoMinutesListAll EXECUTE_DB Error:{0}", strError);
                }
                else
                {
                    strError = string.Empty;
                }
            }
            else
            {
                SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),

                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@ConferenceType",query.ConferenceType),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                  new SqlParameter("@MinutesState",query.MinutesState),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
                CParameters paras = new CParameters();
                paras.AddRange(sqlParameters);

                if (!_db.ExcuteByTransaction(paras, "spGetCInfoMinutesList", out TotalRowsCount, out TotalPageCount, out ds, out strError))
                {
                    strError = string.Format("DBProvider spGetCInfoMinutesList EXECUTE_DB Error:{0}", strError);
                }
                else
                {
                    strError = string.Empty;
                }
            }

            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        ///获取组织会议纪要列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetOrgMinutes(CInfoQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {

                  new SqlParameter("@OrgId",query.OrgId),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);

            if (!_db.ExcuteByTransaction(paras, "spGetOrgMinutes", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrgMinutes EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }


            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据会议ID查看会议纪要信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(DataTable, DataTable)> GetCInfoMinutesByID(CInfoQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",query.CInfoID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoMinutesByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCInfoMinutesByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult((ds.Tables[0], ds.Tables[1]));
        }

        /// <summary>
        /// 会议预约
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(bool, int)> MeetingOrder(MeetingOrder entity, out string strError)
        {

            if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            {
                string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
                                                             //第一个为主会议室

                entity.CRoomID = Convert.ToInt32(arrStr[0]);
                ArrayList list = new ArrayList(arrStr);
            }
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs),
                  new SqlParameter("@PassWords",entity.PassWords),
                  new SqlParameter("@CreateDate",DateTime.Today),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs),
                  new SqlParameter("@CreatorID",entity.CreatorID),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@GroupIDs",entity.GroupIDs),
                  new SqlParameter("@Outsiders",entity.Outsiders),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark),
                  new SqlParameter("@State",entity.State),
                  new SqlParameter("@IsSignIn",entity.IsSignIn),
                  new SqlParameter("@CycleMeetGuid",entity.CycleMeetGuid),
                  new SqlParameter("@CycleMeetType",entity.CycleMeetType),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                  new SqlParameter("@StrategyState",entity.StrategyState),
                  new SqlParameter("@ToDayEnd",entity.ToDayEnd),
                  new SqlParameter("@IsPushEntWechat",entity.IsPushEntWechat),
                  new SqlParameter("@ExchangeItemId",entity.ExchangeItemId),
                  new SqlParameter("@sourceType",entity.sourceType),
                  new SqlParameter("@ItemSort",entity.ItemSort),
                   new SqlParameter("@MasterItemId",entity.MasterItemId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertConferenceInfo", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertConferenceInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (ReturnValue == -2)
            {
                bResult = false;
                strError = "您预约会议室与其他会议的会议室有时间冲突";
            }
            //var tup = new Tuple<bool, int>(bResult, ReturnValue);
            return Task.FromResult((bResult, ReturnValue));
        }
        public Task<bool> InsertMeetingItemId(ItemList entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ItemId",entity.ItemId),
                   new SqlParameter("@exchangeType",entity.exchangeType),
                    new SqlParameter("@IsAuto",entity.IsAuto),
                     new SqlParameter("@CInfoId",entity.meetId),
                     new SqlParameter("@IsSync",entity.ItemId==""?false:true),
                     new SqlParameter("@OrderUser",entity.OrderUser)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertMeetingItemId", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertMeetingItemId EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult((bResult));
        }



        /// <summary>
        /// 会议预约（编辑）******备用编辑
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateConferenceInfo(MeetingOrder entity, out string strError)
        {
            if (entity.ParticipantIDs == null)
            {
                entity.ParticipantIDs = "";
            }
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs),
                  new SqlParameter("@CreatorID",entity.CreatorID),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.EndTime),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@GroupIDs",entity.GroupIDs),
                  new SqlParameter("@Outsiders",entity.Outsiders),
                  new SqlParameter("@EnterWechatNotice",entity.EnterWechatNotice),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark),
                  new SqlParameter("@State",entity.State),
                  new SqlParameter("@ConferenceType",entity.ConferenceType),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceInfo", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 获取会议室及会议信息（首页展示）PC
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPassword"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, DataTable, int, int>> GetCRoomAndCInfo(RoomQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RID",query.RID),
                  new SqlParameter("@CRoomID",query.CRoomID),
                  new SqlParameter("@SearchRID",query.SearchRID),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@ConferenceName",query.ConferenceName),
                  new SqlParameter("@HoldNumber",query.HoldNumber),
                  new SqlParameter("@ConferenceType",query.ConferenceType),
                  new SqlParameter("@CEquipmentIDs",query.CEquipmentIDs),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomAndCInfo", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomAndCInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }
            var tup = new Tuple<DataTable, DataTable, int, int>(ds.Tables[0], ds.Tables[1], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 获取会议室及会议信息（首页展示）Mobile
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPassword"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, DataTable, int, int, bool>> GetMeetRoomAndInfoForMobile(RoomQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RID",query.RID),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomAndCInfoForMobile", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomAndCInfoForMobile EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }
            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, DataTable, int, int, bool>(ds.Tables[0], ds.Tables[1], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 获取会议室及会议信息（首页展示）Pad
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPassword"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, DataTable, DataTable>> GetMeetRoomAndInfoForPad(CRoomPadQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CRoomID",query.CRoomID),
                  new SqlParameter("@PadType",query.PadType),
                  new SqlParameter("@DateTimeNow",DateTime.Now),
                  new SqlParameter("@TodayEnd",DateTime.Today.AddDays(1))
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomAndCInfoForPad", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomAndCInfoForPad EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }

            var tup = new Tuple<DataTable, DataTable, DataTable>(ds.Tables[0], ds.Tables[1], ds.Tables[2]);
            return Task.FromResult(tup);
        }
        public Task<Tuple<DataTable, DataTable>> GetCRoomAndCInfoForPadWithOutColor(CRoomPadQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CRoomID",query.CRoomID),
                  new SqlParameter("@DateTimeNow",DateTime.Now),
                  new SqlParameter("@TodayEnd",DateTime.Today.AddDays(1))
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomAndCInfoForPadWithOutColor", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomAndCInfoForPadWithOutColor EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }

            var tup = new Tuple<DataTable, DataTable>(ds.Tables[0], ds.Tables[1]);
            return Task.FromResult(tup);
        }
        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetCRoomByRID(RoomQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RID",query.RID),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomInfoByRID", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomAndCInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }
            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetCRoomInfoListByRID(RoomQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RID",query.RID),
                  new SqlParameter("@ID",query.ID),

                  new SqlParameter("@IsAdmin",query.IsAdmin),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomInfoListByRID", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomInfoListByRID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;

            }
            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据查询关键字获取所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int, bool>> GetCRoomByKey(RoomQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomInfoByKey", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomInfoByKey EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 管理员查看会议列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetCInfoByAdmin(CInfoQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoByAdmin", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCInfoByAdmin EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 当前登录用户查看会议列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int, bool>> GetCInfoByUser(CInfoQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoByUser", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCInfoByUser EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据会议ID查看会议信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(DataTable, DataTable)> GetCInfoByID(CInfoQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",query.CInfoID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCInfoByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult((ds.Tables[0], ds.Tables[1]));
        }
        public Task<DataTable> GetCInfoByID(int InfoId)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",InfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoByID", out DataSet ds, out string strError))
            {
                strError = string.Format("DBProvider spGetCInfoByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        public Task<DataTable> GetCInfoPwdByID(int InfoId)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",InfoId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCInfoPwdByID", out DataSet ds, out string strError))
            {
                strError = string.Format("DBProvider spGetCInfoPwdByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据会议ID修改会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateMeetingInfoByID(MeetingOrder entity, out string strError)
        {
            string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
            //第一个为主会议室
            entity.CRoomID = Convert.ToInt32(arrStr[0]);
            //ArrayList list = new ArrayList(arrStr);
            //list.RemoveAt(0);
            //entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.CInfoID),
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs),
                  new SqlParameter("@PassWords",entity.PassWords),
                  new SqlParameter("@CreateDate",DateTime.Today),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@Outsiders",entity.Outsiders),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark),
                   new SqlParameter("@State",entity.State),
                   new SqlParameter("@GroupIDs",entity.GroupIDs),
                   new SqlParameter("@ConferenceType",entity.ConferenceType),
                   new SqlParameter("@StrategyState",entity.StrategyState),
                   new SqlParameter("@ToDayEnd",entity.ToDayEnd),
                   new SqlParameter("@ExchangeItemId",entity.ExchangeItemId),
                   new SqlParameter("@MasterItemId",entity.MasterItemId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceInfo", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 提前结束会议
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateMeetingEnd(CInfoQuery entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CinfoId",entity.CInfoID),
                   new SqlParameter("@EndTime",entity.EndTime),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateCInfoEnd", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateCInfoEnd EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 当前登录用户查看参与会议列表（创建，协调，主持，纪要，内部参会）
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int, bool>> GetAllCInfoByUser(CInfoQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                  new SqlParameter("@typeId",query.typeId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllCInfoByUser", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllCInfoByUser EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (TotalRowsCount > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], TotalRowsCount, TotalPageCount, IsHaveNext);
            return Task.FromResult(tup);
        }
        public Task<Tuple<DataTable, int, int, bool>> GetAllCInfoGroupByUser(CInfoQuery query, out string strError)
        {
            bool IsHaveNext = false;
            SqlParameter[] sqlParameters = new SqlParameter[] {


                  new SqlParameter("@DateTimeNow",DateTime.Now),
                  new SqlParameter("@TodayEnd",DateTime.Now.Date.AddDays(1)),
                  new SqlParameter("@AdminType",query.AdminType),
                      new SqlParameter("@RegionalId",query.RegionalId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllCInfoGroupByUser", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllCInfoGroupByUser EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (100 > query.pageIndex * query.pageSize)
            {
                IsHaveNext = false;
            }
            else
            {
                IsHaveNext = true;
            }
            var tup = new Tuple<DataTable, int, int, bool>(ds.Tables[0], 0, 0, IsHaveNext);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 会议转赠
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> TransferMeeting(TransferMeeting entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@Transfer",entity.Transfer),
                  new SqlParameter("@CreatorID",entity.CreatorID),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spTransferCRoom", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spTransferCRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 会议延长
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> ExtendMeeting(ExtendMeeting entity, out string strError)
        {
            entity.EndTime = entity.EndTime.AddMinutes(entity.Extend);
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@Extend",entity.Extend),
                  new SqlParameter("@EndTime",entity.EndTime),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spExtendCRoom", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spExtendCRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 删除(取消)会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> DeleteMeetingInfo(TransferMeeting entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spDeleteCInfo", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider DeleteMeetingInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 添加会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> AddMeetingEquipment(MeetingEquipment entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@EquipmentName",entity.EquipmentName),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertConferenceEquipment", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertConferenceEquipment EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 删除会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> DeleteMeetingEquipment(MeetingEquipment entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spDeleteConferenceEquipment", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteConferenceEquipment EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 根据ID修改会议设备名称
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateMeetingEquipment(MeetingEquipment entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@EquipmentName",entity.EquipmentName),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceEquipment", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceEquipment EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 根据查询关键字获取所有会议设备信息    
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetMeetingEquipment(EquipmentQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetConferenceEquipment", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetConferenceEquipment EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据会议ID和时间查看是否有预约会议室时间冲突
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(DataTable, DataTable)> GetRoomInfoByTime(CRoomTimeQuery query, out string strError)
        {
            string[] arrStr = query.CRoomIDs.Split(',');//按逗号截取  
            //第一个为主会议室
            var CRoomID = Convert.ToInt32(arrStr[0]);
            ArrayList list = new ArrayList(arrStr);
            list.RemoveAt(0);
            query.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CInfoID",query.CInfoID),
                  new SqlParameter("@CRoomID",CRoomID),
                  new SqlParameter("@roomId",query.CRoomIDs),
                  new SqlParameter("@begintime",query.BeginTime),
                  new SqlParameter("@endtime",query.EndTime),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRoomInfoByTime", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetRoomInfoByTime EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult((ds.Tables[0], ds.Tables[1]));
        }

        /// <summary>
        /// 会议审批
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> ApprovalMeeting(ApprovalMeeting entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@Approval",entity.Approval),
                  new SqlParameter("@procInstID",entity.procInstID),
                  new SqlParameter("@TYPE",entity.TYPE),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spApprovalMeeting", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spApprovalMeeting EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 根据用户ID查看是否有会议纪要48小时内没有上传
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> CheckMinutes(CheckMinutesQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@CheckTime",DateTime.Now),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spCheckMinutes", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spCheckMinutes EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据用户ID获取用户当天创建会议数（单人每天创建会议不超过两次）
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetMeetingCountByUserID(UserIDAndTime query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetMeetingCountByUserID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetMeetingCountByUserID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        public Task<(bool, int, string)> SignInCInfo(string mobile, string cinfoId)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@phone",mobile),
                  new SqlParameter("@CInfoId",cinfoId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spSignInCinfobyPhone", out DataSet Dt, out string strError))
            {
                strError = string.Format("DBProvider spSignInCinfobyPhone EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var ReturnValue = int.Parse(Dt.Tables[0].Rows[0]["res"].ToString());
            return Task.FromResult((ReturnValue > 0, ReturnValue, strError));
        }
        /// <summary>
        /// 查询当前会议的下一条会议是否能签到
        /// </summary>
        /// <param name="user"></param>
        /// <param name="cinfoId"></param>
        /// <param name="firstCInfoId"></param>
        /// <returns></returns>
        public Task<(bool, int, string)> SencondSignInCInfo(string user, string cinfoId, string firstCInfoId)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@phone",user),
                  new SqlParameter("@CInfoId",cinfoId),
                  new SqlParameter("@firstCInfoId",firstCInfoId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spSignInSencondCinfobyPhone", out DataSet Dt, out string strError))
            {
                strError = string.Format("DBProvider spSignInSencondCinfobyPhone EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var ReturnValue = int.Parse(Dt.Tables[0].Rows[0]["res"].ToString());
            return Task.FromResult((ReturnValue > 0, ReturnValue, strError));
        }
        public Task<(bool, int, string)> GetRoomQCState(string croomId)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CroomId",croomId)
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetRoomQCState", out DataSet Dt, out string strError))
            {
                strError = string.Format("DBProvider spGetRoomQCState EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var ReturnValue = int.Parse(Dt.Tables[0].Rows[0]["AutoWechat"].ToString());
            return Task.FromResult((ReturnValue > 0, ReturnValue, strError));
        }

        /// <summary>
        /// 获取会议须知
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetConferenceNotice(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetConferenceNotice", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetConferenceNotice EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 获取会议室审批
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetCRoomApproval(ConferenceRoom query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                new SqlParameter("@CRoomID",query.ID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomApproval", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomApproval EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据ID修改会议须知
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateConferenceNotice(ConferenceNotice entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@NoticeContent",entity.NoticeContent),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateConferenceNotice", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateConferenceNotice EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 扣除用户积分（纪要在规定时间内没有上传）
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> MinutesPointsDeducted(CheckMinutesEntity entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spMinutesPointsDeducted", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spMinutesPointsDeducted EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }
        public Task<DataSet> spGetCroomInfoByRoomId(string croomId, out string strError)
        {


            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@RoomId",croomId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCroomInfoByRoomId", out DataSet ds, out strError))
            {

                strError = string.Format("DBProvider spGetCroomInfoByRoomId EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(ds);
        }

        /// <summary>
        /// 根据查询关键字转赠记录    
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetTransferRecord(TransferMeeting query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@Type",query.Type),
                  new SqlParameter("@UserID",query.UserID),
                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetTransferRecord", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetTransferRecord EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 根据组织ID查询组织日历信息    
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetOrgCalendars(CalendarsMeetQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@OrgId",query.OrgId),
                  new SqlParameter("@BeginTime",query.BeginTime),
                  new SqlParameter("@EndTime",query.EndTime),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetOrgcalendars", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrgcalendars EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        /// <summary>
        /// 获取所有会议室信息
        /// </summary>
        /// <returns></returns>
        public Task<DataTable> GetAllMeetingRoom(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllMeetingRoom", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllMeetingRoom EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        /// <summary>
        /// 微信会议室ID
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdateRoomWXID(int ID, int wxid, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),
                  new SqlParameter("@wxid",wxid),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateRoomWXID", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateRoomWXID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 根据会议ID绑定微信日程关联ID
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> UpdatecCInfoSchedule_id(int ID, string Schedule_id, out string strError)
        {

            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),
                  new SqlParameter("@Schedule_id",Schedule_id),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdatecCInfoSchedule_id", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdatecCInfoSchedule_id EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }
        /// <summary>
        /// 检查视频会议室密码是否唯一
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<bool> GheckPassWord(string password, DateTime date, out int ReturnValue)
        {
            string strError = string.Empty;
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@PassWord",password),
                  new SqlParameter("@CreateDate",date),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spCheckPassWord", out ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spCheckPassWord EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 会议室策略说明
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetStrategyInfo(out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetStrategyInfo", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetStrategyInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 会议室策略
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetStrategyInfoByID(StrategyInfo query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                new SqlParameter("@StrategyId",query.StrategyId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetStrategyInfoByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider GetStrategyInfoByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 根据ID获取会议室类型
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<DataTable> GetCRoomTypeByID(ConferenceRoom query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {

                new SqlParameter("@ID",query.ID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetCRoomTypeByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetCRoomTypeByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }

        /// <summary>
        /// 查看所有会议信息会议室密码
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<DataTable, int, int>> GetAllCInfoPassWord(CInfoQuery query, out string strError)
        {

            SqlParameter[] sqlParameters = new SqlParameter[] {

                  new SqlParameter("@Key",query.Key),
                  new SqlParameter("@PageIndex",query.pageIndex),
                  new SqlParameter("@PageSize",query.pageSize),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllCInfoPassWord", out int TotalRowsCount, out int TotalPageCount, out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllCInfoPassWord EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            var tup = new Tuple<DataTable, int, int>(ds.Tables[0], TotalRowsCount, TotalPageCount);
            return Task.FromResult(tup);
        }

        /// <summary>
        /// 新增组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<bool, int>> OrgcalendarsOrder(MeetingOrder entity, out string strError)
        {
            bool bResult = true;


            if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            {
                string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
                                                             //第一个为主会议室

                entity.CRoomID = Convert.ToInt32(arrStr[0]);
                ArrayList list = new ArrayList(arrStr);
                //list.RemoveAt(0);
                //entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            }
            entity.ConferenceType = 2;


            entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
            entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);


            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@CostomCRoom",entity.CostomCRoom),
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs??""),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs??""),
                  new SqlParameter("@CreatorID",entity.CreatorID),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme??""),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@Outsiders",entity.Outsiders??""),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark??""),
                   new SqlParameter("@RID",entity.RID),
                   new SqlParameter("@State",1),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertOrgcalendars EXECUTE_DB Error:{0}", strError);
            }

            return Task.FromResult(new Tuple<bool, int>(bResult, ReturnValue));
        }
        /// <summary>
        /// 编辑组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<bool, int>> UpdateOrgcalendars(MeetingOrder entity, out string strError)
        {
            bool bResult = true;


            if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            {
                string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
                                                             //第一个为主会议室

                entity.CRoomID = Convert.ToInt32(arrStr[0]);
                ArrayList list = new ArrayList(arrStr);
                list.RemoveAt(0);
                entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            }
            entity.ConferenceType = 2;


            entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
            entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);


            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),
                  new SqlParameter("@CostomCRoom",entity.CostomCRoom),
                  new SqlParameter("@CRoomID",entity.CRoomID),
                  new SqlParameter("@CRoomIDs",entity.CRoomIDs??""),
                  new SqlParameter("@ParticipantIDs",entity.ParticipantIDs??""),
                  //new SqlParameter("@CreatorID",entity.CreatorID),
                  new SqlParameter("@ConferenceTheme",entity.ConferenceTheme??""),
                  new SqlParameter("@BeginTime",entity.BeginTime),
                  new SqlParameter("@EndTime",entity.EndTime),
                  new SqlParameter("@TimeLength",entity.TimeLength),
                  new SqlParameter("@Coordinator",entity.Coordinator),
                  new SqlParameter("@HostPerson",entity.HostPerson),
                  new SqlParameter("@MinutesPerson",entity.MinutesPerson),
                  new SqlParameter("@Outsiders",entity.Outsiders??""),
                  new SqlParameter("@ConferenceRemark",entity.ConferenceRemark??""),
                   //new SqlParameter("@ConferenceType",entity.ConferenceType),
                  //new SqlParameter("@State",entity.State),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertOrgcalendars EXECUTE_DB Error:{0}", strError);
            }

            return Task.FromResult(new Tuple<bool, int>(bResult, ReturnValue));
        }
        /// <summary>
        /// 取消组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<Tuple<bool, int>> DeleteOrgcalendars(MeetingOrder entity, out string strError)
        {
            bool bResult = true;


            //if (entity.CRoomIDs != "" && entity.CRoomIDs != null)
            //{
            //    string[] arrStr = entity.CRoomIDs.Split(',');//按逗号截取  
            //                                                 //第一个为主会议室

            //    entity.CRoomID = Convert.ToInt32(arrStr[0]);
            //    ArrayList list = new ArrayList(arrStr);
            //    list.RemoveAt(0);
            //    entity.CRoomIDs = string.Join(",", (string[])list.ToArray(typeof(string)));
            //}
            //entity.ConferenceType = 2;


            //entity.BeginTime = Convert.ToDateTime(entity.Date + " " + entity.Begin);
            //entity.EndTime = Convert.ToDateTime(entity.Date + " " + entity.End);


            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",entity.ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spDeleteOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spDeleteOrgcalendars EXECUTE_DB Error:{0}", strError);
            }

            return Task.FromResult(new Tuple<bool, int>(bResult, ReturnValue));
        }

        /// <summary>
        /// 根据ID查看组织日历信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(DataTable, DataTable, DataTable)> GetOrgcalendarsByID(CInfoQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",query.CInfoID),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetOrgcalendarsByID", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetOrgcalendarsByID EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult((ds.Tables[0], ds.Tables[1], ds.Tables[2]));
        }

        /// <summary>
        /// 会议预约添加进日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public (bool, int) InsertCInfoToOrgcalendars(int ID, out string strError)
        {


            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spInsertCInfoToOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spInsertCInfoToOrgcalendars EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            //var tup = new Tuple<bool, int>(bResult, ReturnValue);
            return (bResult, ReturnValue);
        }
        /// <summary>
        /// 根据会议ID查询关联组织公共日历ID
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public (bool, int) ChickOrgcalendarsIsHaveCInfo(int ID, out string strError)
        {


            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spChickOrgcalendarsIsHaveCInfo", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spChickOrgcalendarsIsHaveCInfo EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            //var tup = new Tuple<bool, int>(bResult, ReturnValue);
            return (bResult, ReturnValue);
        }

        /// <summary>
        /// 根据会议ID修改关联组织公共日历ID
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public (bool, int) UpdateCInfoToOrgcalendars(int ID, out string strError)
        {


            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spUpdateCInfoToOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spUpdateCInfoToOrgcalendars EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            //var tup = new Tuple<bool, int>(bResult, ReturnValue);
            return (bResult, ReturnValue);
        }

        public (bool, int) deleteCInfoToOrgcalendars(int ID, out string strError)
        {


            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@ID",ID),


                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spdeleteCInfoToOrgcalendars", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spdeleteCInfoToOrgcalendars EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            //var tup = new Tuple<bool, int>(bResult, ReturnValue);
            return (bResult, ReturnValue);
        }
        public Task<DataTable> GetAllColor(int padType, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@PadType",padType),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllColor", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllColor EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[0]);
        }
        public Task<DataTable> GetStateColorByPadType(int padType, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@PadType",padType),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spGetAllColor", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spGetAllColor EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult(ds.Tables[1]);
        }
        public Task<bool> PadColorUpdate(StateColorQuery entity, out string strError)
        {
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@PadType",entity.PadType),
                  new SqlParameter("@LightStateId",entity.LightStateId),
                       new SqlParameter("@ColorId",entity.ColorId),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spPadColorUpdate", out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spPadColorUpdate EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            return Task.FromResult(bResult);
        }

        public Task<bool> CheckUserHaveCalendarsAuth(MeetingOrder entity, out string strError)
        {
            strError = string.Empty;
            bool bResult = true;
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@UserID",entity.loginuserid),
                  new SqlParameter("@RID",entity.RID),

                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spCheckUserHaveCalendarsAuth", out int ReturnValue, out strError))
            {
                bResult = false;
                strError = string.Format("DBProvider spCheckUserHaveCalendarsAuth EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }
            if (ReturnValue > 0)
            {

                bResult = true;
            }
            else
            {
                strError = "您没有该组织的日历更新操作权限";
                bResult = false;
            }
            return Task.FromResult(bResult);
        }

        /// <summary>
        /// 快速预定会议室
        /// </summary>
        /// <param name="query"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Task<(DataTable, DataTable, DataTable)> QuicklyMeetingOrder(CInfoQuery query, out string strError)
        {
            SqlParameter[] sqlParameters = new SqlParameter[] {
                  new SqlParameter("@BeginTime",query.BeginTime),
                   new SqlParameter("@EndTime",query.EndTime),
                    new SqlParameter("@EndDate",DateTime.Now.Date.AddHours(23).AddMinutes(59)),
                };
            CParameters paras = new CParameters();
            paras.AddRange(sqlParameters);
            if (!_db.ExcuteByTransaction(paras, "spQuicklyMeetingOrder", out DataSet ds, out strError))
            {
                strError = string.Format("DBProvider spQuicklyMeetingOrder EXECUTE_DB Error:{0}", strError);
            }
            else
            {
                strError = string.Empty;
            }

            return Task.FromResult((ds.Tables[0], ds.Tables[1], ds.Tables[2]));
        }
    }
}
